package com.keydom.ropeskipping.adapter;

import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.clj.fastble.data.BleDevice;
import com.keydom.ropeskipping.R;

import java.util.List;

public class ScanItemAdapter extends BaseQuickAdapter<BleDevice, BaseViewHolder> {

    public ScanItemAdapter(int layoutResId, @Nullable List<BleDevice> data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(@NonNull BaseViewHolder helper, final BleDevice bleData) {
        TextView tvName = helper.itemView.findViewById(R.id.text_name);
        TextView tvMac = helper.itemView.findViewById(R.id.text_mac);
        ImageView imageConnect = helper.itemView.findViewById(R.id.image_connect);
        tvName.setText(bleData.getName());
        tvMac.setText(bleData.getMac());
        imageConnect.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                onItemClickListener.onItemClick(bleData);
            }
        });
    }

    public interface OnItemClickListener{
        void onItemClick(BleDevice bluetoothDevice);
    }

    protected OnItemClickListener onItemClickListener;

    public void setOnItemClickListener(OnItemClickListener onItemClickListener) {
        this.onItemClickListener = onItemClickListener;
    }
}
